package com.example.user.util;



import java.sql.*;

public class TestTansaction {
    public static void main(String[] args) throws SQLException {
        Connection con = null;      //放在外面防止关不掉
        PreparedStatement pst = null;
        ResultSet re = null;
        //con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.131:1521:orcl", "b18_pes", "333");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/szx?serverTimezone=GMT%2B8", "root", "333333");
        con.setAutoCommit(false);         //关闭自动提交，自动开启事务
        pst = con.prepareStatement("select * from person01");     //可以不带参数
        re = pst.executeQuery();
//        con.rollback();                    出错默认回滚

        while (re.next()) {
            System.out.println(re.getInt("id"));
        }
        re.close();
        pst.close();
        con.close();
    }
}
